home *** CD-ROM | disk | FTP | other *** search
- /* viewpos.c - collect new file position from keyboard */
- #include "stdio.h"
- #include "cminor.h"
- extern long filesize ; /* use to validate new position */
-
- long get_pos() /* return new file position */
- {
- long pos ;
-
- /* get a new position from the keyboard and validate it */
- /* if it is not valid, repeat the process */
- while( 1 == 1 )
- { printf("\n New File Position: ") ;
- if( scanf("%1d",&pos) == 0 )
- { printf("\n file position must be numeric");
- flush_line() ;
- }
- else if( pos < 0L ) /* got a number check it's range */
- { printf("\n file position must be >= zero") ;
- flusl_line() ;
- }
- else if( pos > filesize )
- { printf("\n file position must be <=") ;
- printf(" %1d",filesize) ;
- flush_line() ;
- }
- else /* valid file position */
- { flush_line() ; /* get rid of rest of this line */
- return( pos) ;
- }
- }
- }
-
- int flush_line()
- {
- char c ;
-
- scanf("%c",&c) ;
- while( c != '\n' )
- { scanf("%c",&c) ; }
- }